// define register
export enum AUTH_ENUM {
  SIGNUP = "SIGNUP",
  SIGNUP_SUCCESS = "SIGNUP_SUCCESS",
  SIGNUP_FAIL = "SIGNUP_FAIL",
  RESET_SIGNUP = "RESET_SIGNUP",
}

export interface SignupPayload {
  email: string;
  name: string;
  password: string;
}

export interface SignupAction {
  type: typeof AUTH_ENUM.SIGNUP;
  payload: SignupPayload;
}

export interface SignupSuccessAction {
  type: typeof AUTH_ENUM.SIGNUP_SUCCESS;
}

export interface SignupFailAction {
  type: typeof AUTH_ENUM.SIGNUP_FAIL;
  message: string;
}

export interface ResetSignupAction {
  type: typeof AUTH_ENUM.RESET_SIGNUP;
}

export const signup = (payload: SignupPayload): SignupAction => {
  return {
    type: AUTH_ENUM.SIGNUP,
    payload,
  };
};

export const signupSuccess = (): SignupSuccessAction => {
  return {
    type: AUTH_ENUM.SIGNUP_SUCCESS,
  };
};

export const signupFail = (message: string): SignupFailAction => {
  return {
    type: AUTH_ENUM.SIGNUP_FAIL,
    message,
  };
};

export const resetSignupAction = (): ResetSignupAction => {
  return {
    type: AUTH_ENUM.RESET_SIGNUP,
  };
};
// define login
export const LOGIN_ENUM = {
  SIGNIN: "SIGNIN",
  SIGNIN_SUCCESS: "SIGNIN_SUCCESS",
  SIGNIN_FAIL: "SIGNIN_FAIL",
};

export interface SigninPayload {
  email: string;
  password: string;
}

export interface SigninAction {
  type: typeof LOGIN_ENUM.SIGNIN;
  payload: SigninPayload;
}

export interface SigninSuccessAction {
  type: typeof LOGIN_ENUM.SIGNIN_SUCCESS;
}

export interface SigninFailAction {
  type: typeof LOGIN_ENUM.SIGNIN_FAIL;
  message: string;
}

export const signin = (payload: SigninPayload): SigninAction => {
  return {
    type: LOGIN_ENUM.SIGNIN,
    payload,
  };
};

export const signinSuccess = (): SigninSuccessAction => {
  return {
    type: LOGIN_ENUM.SIGNIN_SUCCESS,
  };
};

export const signinFail = (message: string): SigninFailAction => {
  return {
    type: LOGIN_ENUM.SIGNIN_FAIL,
    message,
  };
};

export type AuthUnionType =
  | SignupAction
  | SignupSuccessAction
  | SignupFailAction
  | ResetSignupAction
  | SigninAction
  | SigninSuccessAction
  | SigninFailAction;
